<?php

namespace App\Console\Commands;

use App\Jobs\MintJob;
use App\Models\Nft;
use App\Models\Setting;
use Illuminate\Console\Command;

class Mint extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:mint';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        //判断挖矿是否开启
        $setting = Setting::where('key', 'mint_enable')->first();
        if ($setting) {
            if ($setting->value == 0) {
                return;
            }
        } else {
            return;
        }
        $nfts = Nft::whereRaw('days > minted_days')->get();

        foreach ($nfts as $nft) {
            MintJob::dispatch($nft)->onQueue('mint');
        }
    }
}
